

var newer = newer || {};
newer.gd = newer.gd || {};

newer.FriendsDiv = function(o) {
	this.domNode = o.domNode;
	this.prt = o.prt;	
	
	this.init();
}

newer.FriendsDiv.prototype = {

	init: function() {
		this.domNode.html("");
		
		this.domNode.removeClass("nw-event-listener").addClass("nw-event-listener");
		this.domNode.on("nw-event", $.proxy(this.nweHandler,this));
		
		this.refresh();
	}, 
	
	refresh: function() {
		this.update();
	},
	
	nweHandler: function(e,c) {
		if (c.type == newer.EventHelper.DATA_TYPE) {
			if (c.props.type == "friend") {
				this.refresh();
			}
		}
	},
	
	update: function() {
		this.domNode.html("");
		this.domNode.html('<div id="friends-11-div" class="people-gallery-area"></div><div id="friends-01-div" class="people-gallery-area"></div><div id="friends-10-div class="people-gallery-area""></div>');
		this.friendsNode11 = $("#friends-11-div");
		this.friendsNode01 = $("#friends-01-div");
		this.friendsNode10 = $("#friends-10-div");
		
		this.showFriends(this.friendsNode11,"0");
		this.showFriends(this.friendsNode01,"1");
		this.showFriends(this.friendsNode10,"2");
		
	}, 

	showOneFriend: function(person) {
		var res = "<div class=\"inline-block\"><img height=150px id=\"f" + person.id +"\" class=\"friends-photo-img\"></div>";
		return res;
	},
	
	showFriends: function(node,type) {
		var self = this;
		
		switch(type) {
			case "0": 
				node.html("<div>互相加为好友的Newer：</div>");
				break;
			case "1": 
				node.html("<div>加您为好友的Newer：</div>");
				break;
			case "2": 
				node.html("<div>您加为好友的Newer：</div>");
				break;
		}
		
		$.post("/Friends/getFriendsJSON", {"pid":newer.gd.people.id,"type":type}, function(result) {
			if (result == false) {
			} else {
				$(node).append('<div id="'+type+'t"></div>');
				$.each(result, function(index, friend) {
					
					$('#'+type+'t').append('<div class="inline-block" id="f'+friend.id+'"></div>');
					new newer.PeopleCard({
						domNode: $("#f"+friend.id),
						idSuffix: "list-"+friend.id,
						personInfo: friend
					});

				});
			}
		}, "json");
	}
}